package buttons;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Font;
import org.newdawn.slick.geom.Circle;

import states.SlickGame;

public class CircleToggleButton extends Button{
	float r;
	public boolean disable;
	Color normalColor,activeColor,borderColor,textColor;
	String text;
	int delay, curTime;
	
	public CircleToggleButton(int X, int Y, float R, String t) {
		super(X, Y); r=R; text=t; delay=SlickGame.fps*4; curTime=delay;
		this.normalColor=Color.gray; this.activeColor=Color.gray.addToCopy(Color.red); this.borderColor=Color.gray.darker(); this.textColor=Color.gray.brighter();
	}
	
	public CircleToggleButton(int X, int Y, float R, String t,Color n, Color a, Color b) {
		super(X, Y); r=R; text=t; delay=SlickGame.fps*2; curTime=delay;
		this.normalColor=n; this.activeColor=a; this.borderColor=b; this.textColor=Color.gray.brighter();
	}
	// make full constructor.
	
	public void update(int mx, int my, boolean isMouseDown, int delta){
		curTime+=delta;
		if(isMouseDown && curTime>delay && !disable){ // mouse click?
			if(Math.hypot(x-mx, y-my)<r){ // inside range?
				curTime=0;
				this.clicked=!clicked;
			}
			else{
				
			}
		}
	}
	
	public void draw(Graphics g){
		g.setLineWidth((float) 1.5);
		g.setColor(borderColor);
		g.draw(new Circle(x,y,r+1));
		if(disable){
			g.setColor(Color.gray);
		}
		else if(this.clicked){
			g.setColor(activeColor);
		}
		else{
			g.setColor(normalColor);
		}
		g.draw(new Circle(x,y,r));
		
		g.resetLineWidth();
		Color bgColor=g.getColor();
		bgColor.a=(float) 0.2;
		g.setColor(bgColor.darker());
		g.fill(new Circle(x,y,r));
		g.setColor(textColor);
		int tWidth,tHeight;
		tWidth=g.getFont().getWidth(text);
		tHeight=g.getFont().getHeight(text);
		g.drawString(text, x-tWidth/2, y-tHeight/2-r-10);
		
		
	} // draw CircleToggle Button
	
}
